/*
 * @Author: jiayu
 * @Date: 2022-08-10 10:20:00
 * @LastEditors: jiayu
 * @LastEditTime: 2023-07-27 10:51:05
 * @Description: 
 */
import { getDep } from "@/services/jy-api/api"
import { useState,useEffect } from "react"

export default function OrganizationalModels() {
  const [data, setData] = useState<any[]>([])
  const [currentPosi, setCurrentPosi] = useState<any[]>([])
  const [currentDepartmentId, setCurrentDepartmentId] = useState('')


  const fetchData = () => {
    console.log(1232131231)
    getDep().then(data => {
      setData(data.data)
      setCurrentPosi([data.data[0]])
    })
  }

  useEffect(() => {
    fetchData()
  }, [])


  useEffect(() => {
    if (currentPosi.length > 0) {
      setCurrentDepartmentId(currentPosi[currentPosi.length - 1].id)
    }
  }, [currentPosi])

  return {
    data,
    currentPosi,
    setCurrentPosi,
    currentDepartmentId
  }
}


